<template>
  <div>
    <el-steps :active="active" simple>
      <el-step title="创建试卷" icon="el-icon-edit"></el-step>
      <el-step title="添加试题" icon="el-icon-upload"></el-step>
      <el-step title="发布考试" icon="el-icon-picture"></el-step>
    </el-steps>


    <div class="card">
      <el-radio v-model="status" label="0">创建新试卷</el-radio>
      <div v-if="status==='0'">
        <el-form :model="dataForm" :rules="rules" ref="dataForm" label-width="100px" class="demo-ruleForm" style="margin-top: 20px">
          <el-form-item label="试卷名称" prop="name">
            <el-input v-model="dataForm.name" style="width: 500px"></el-input>
          </el-form-item>
          <el-form-item label="试卷分类" prop="cateId">
            <el-select v-model="dataForm.cateId" filterable placeholder="请选择">
              <el-option
                v-for="item in cateList"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="组卷方式">
            <el-radio-group v-model="dataForm.compType">
              <el-radio-button label="0">选题组卷</el-radio-button>
              <el-radio-button label="1">抽题组卷</el-radio-button>
              <el-radio-button label="2">随机组卷</el-radio-button>
            </el-radio-group>
          </el-form-item>
          <el-form-item>
            <el-button  type="primary" @click="handlerNext">下一步</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <div class="card">
      <el-radio v-model="status" label="1">从试卷库中选择一张试卷</el-radio>
      <div v-if="status==='1'">bbb</div>
    </div>
  </div>
</template>

<script>
  export default {
    data () {
      return {
        status: '0',
        active: 0,
        cateList: [],
        dataForm: {
          name: '',
          cateId: '',
          compType: 0
        },
        rules: {
          name: [
            { required: true, message: '试卷不能为空', trigger: 'blur' }
          ],
          cateId: [
            { required: true, message: '试卷分类不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    mounted () {
      this.getCateList()
    },
    methods: {
      // 获取数据列表
      getCateList () {
        this.$http({
          url: this.$http.adornUrl('/exam-admin/paper/cate/select'),
          method: 'post'
        }).then(data => {
          if (data) {
            this.cateList = data.data
          } else {
            this.cateList = []
          }
        })
      },
      handlerNext () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$router.push({
              name: 'paper-add',
              query: {
                name: this.dataForm.name,
                cateId: this.dataForm.cateId,
                compType: this.dataForm.compType
              }
            })
          }
        })
      }
    }
  }
</script>

<style scoped>
.card {
  padding: 20px;
  box-shadow: 0 0 8px 0 rgba(47,124,219,0.40);
  border-radius: 8px;
  margin-top: 30px;
}
</style>
